/**
 * 是否是中文
 * @param {string} text 内容
 * @returns {boolean}
 */
export const isChinese = (text) => {
    return /^[\u4e00-\u9fa5]+$/.test(text)
}

/**
 * 是否是手机号
 * @param {string | number} phone 内容
 * @returns {boolean}
 */
export const isPhone = (phone) => {
    return /^1(3|4|5|6|7|8|9)\d{9}$/.test(phone)
}

/**
 * 姓名
 * @param {string} name 姓名
 * @returns {boolean}
 */
export const isName = (name) => {
    return /^[\u4E00-\u9FA5]{2,10}(·[\u4E00-\u9FA5]{2,10}){0,2}$/.test(name)
}

/**
 * 是否是邮箱
 * @param {string} email 邮箱
 * @returns {boolean}
 */
export const isEmail = (email) => {
    return /[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(email)
}

/**
 * 是否是发票抬头
 * @param {string} lookup 内容
 * @returns {boolean}
 */
export const isLookup = (lookup) => {
    return /^[\u4E00-\u9FA5]{2,10}(·[\u4E00-\u9FA5]{2,10}){0,2}$/.test(lookup) && lookup.length > 4;
}

/**
 * 是否是税号
 * @param {string} test 内容
 * @returns {boolean}
 */
export const isDutyParagraph = (test) => {
    return /^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/.test(test)
}
// 是否是邮箱
export const isEmails = (email) => {
    return  /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)
}

/**
 * 是否是地址url
 * @param {string} url
 * @returns {Boolean}
 */
export function validURL(url) {
    const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
    return reg.test(url)
}

/**
 * 是否是数组
 * @param {Array} arg
 * @returns {Boolean}
 */
export function isArray(arg) {
    if (typeof Array.isArray === 'undefined') {
        return Object.prototype.toString.call(arg) === '[object Array]'
    }
    return Array.isArray(arg)
}
